package in.muton.edushare.pages.coursepages;

import in.muton.edushare.panels.assignment.CreateAssignment;
import in.muton.edushare.url.EntityPageParams;
import in.muton.edushare.wicket.models.CayenneModel;

import java.util.Arrays;

import org.apache.wicket.PageParameters;

import com.edushare.common.constants.ApplicationConstants;
import com.edushare.common.vo.CourseInstances;
import com.edushare.common.vo.Enrolments;

public class CourseAssignmentCreation extends CourseBase {

	public CourseAssignmentCreation(final PageParameters params) {
		super(params);
		prc.check(Arrays.asList(Enrolments.TEACHER, Enrolments.TEACHING_ASSISTANT));
		CourseInstances ci = getCourseInstance().getObject();
		prc.check(Arrays.asList(Enrolments.TEACHER, Enrolments.TEACHING_ASSISTANT));
		
		add(new CreateAssignment("assnCreatePanel", new CayenneModel<CourseInstances>(ci), this){
			
			private static final long serialVersionUID = 8632452922090753251L;

			@Override
			protected void afterAssignmentCreation() {
				super.afterAssignmentCreation();				
				setResponsePage(CourseAssignmentList.class, EntityPageParams.getParams(getCourse()));
			}
			
			@Override
			protected void afterSaveAsDraft() {
				setResponsePage(CourseAssignmentList.class, EntityPageParams.getParams(getCourse()));
			}
			
			@Override
			protected void afterAssignmentDiscarded() {
				super.afterAssignmentDiscarded();
				setResponsePage(CourseAssignmentList.class, EntityPageParams.getParams(getCourse()));
			}
			
		});
	}

	@Override
	protected String getActivePage(PageParameters params) {
		// TODO Auto-generated method stub
		return "viewAssn";
	}

	@Override
	public String getPageTitle() {
		return getLoggedInUser().getCompleteUserName() + " | "
		+ getCourse().getObject().getCourseName()
		+ " | Create Assignment | "
		+ ApplicationConstants.APPLICATION_NAME;		
	}

}
